import request from '@/utils/request'

export function login(data) {
  if (data.type === 'sid') {
    data.type = undefined
    return request({
      url: '/sys/login',
      method: 'post',
      data: {
        school_number: data.username,
        password: data.password,
        uuid: data.uuid,
        code: data.captcha
      }
    })
  } else {
    data.type = undefined
    return request({
      url: '/sys/loginByPhone',
      method: 'post',
      data: {
        phone: data.username,
        code: data.phoneCaptcha,
        imageCode: data.captcha,
        uuid: data.uuid
      }
    })
  }
}

export function getCaptcha() {
  return request({
    url: '/sys/verificationCode',
    method: 'get'
  })
}

export function sendPhoneCaptcha(phoneNumber) {
  return request({
    url: '/sys/send/' + phoneNumber,
    method: 'post'
  })
}

export function getInfo() {
  return request({
    url: '/user/getInfo',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/vue-element-admin/user/logout',
    method: 'post'
  })
}

export function resetPwd(id, oldPassword, newPassword) {
  return request({
    url: '/user/rePassword', method: 'get',
    params: {id, oldPassword, newPassword}
  })
}

export function getList(query) {
  return request({
    url: '/user',
    method: 'get',
    params: query
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: '/user/' + id,
    method: 'delete'
  })
}

// 新建用户
export function addUser(data) {
  data.type = undefined
  return request({
    url: '/user',
    method: 'post',
    data
  })
}

export function resetPassword(id) {
  return request({
    url: '/user/rePassword?id=' + id,
    method: 'get'
  })
}

// 修改用户信息
export function updateArticle(data) {
  data.type = undefined
  return request({
    url: '/user/',
    method: 'put',
    data
  })
}
